﻿
@SYSTEM_TITLE

; CALL RECORD_TICK
STOPBGM
REDRAW 0
LOADGLOBAL

BEGIN FIRST

;===========================================

@EVENTFIRST
#LATER

ARRAYMSORT ALL_LIST_NAME, ALL_LIST
CALL GAME_TITLE

;===========================================

@GAME_TITLE

ALIGNMENT CENTER
ALL_LIST_COUNT = VARSIZE("ALL_LIST") - MATCH(ALL_LIST, "")

CALL GET_GAME_TITLE

$LOOP_1

SETBGMVOLUME 40
PLAYBGM "MMS.aac"

$LOOP_2

CLEARLINE LINECOUNT

DRAWLINE
PRINTL
PRINTSL GAME_TITLE
PRINTSL GAME_TITLE:1
PRINTS "\n" * 2
PRINTL [0] 开始游戏
IF GLOBAL
	PRINTL [1] 品鉴列表
ELSE
	PRINTL [1] 读取存档
ENDIF
PRINTL
DRAWLINE

INPUT
CLEARLINE 1

IF RESULT == 1 && GLOBAL
	ALIGNMENT LEFT
	PRINTL
	FOR LOCAL, 0, ALL_LIST_COUNT
		PRINTFORML [{LOCAL}] %ALL_LIST_NAME:LOCAL%
	NEXT
	PRINTL
	DRAWLINE
	PRINTL
	PRINTFORMLC [{ALL_LIST_COUNT}] 已经品鉴的够多了
	PRINTL
	ALIGNMENT CENTER
	INPUT
	CLEARLINE 1
	IF INRANGE(RESULT, 0, ALL_LIST_COUNT - 1)
		CALL PLAY_CURRENT_LIST(ALL_LIST:RESULT)
	ELSE
		GOTO LOOP_2
	ENDIF
ELSE
	CALL PLAY_CURRENT_LIST
ENDIF

GOTO LOOP_1

;===========================================

@PLAY_CURRENT_LIST(ARGS)

#DIM LOADING_OFFSET

LOADING_OFFSET = GETMILLISECOND()
STOPBGM
PLAYSOUND "HOLOTAPE_LOADING.wav"

CLEARLINE LINECOUNT
ALIGNMENT LEFT
PRINTL 正在读取，请稍等。。。
ALIGNMENT CENTER
AWAIT

CURRENT_LYRIC = 0
LYRIC_DIRECTION = 0

IF ARGS == ""
	IF GLOBAL && CURRENT_LIST != ""
		LOCAL = FINDELEMENT(ALL_LIST, CURRENT_LIST, , , 1) + 1
		CURRENT_LIST '= ALL_LIST:(LOCAL % ALL_LIST_COUNT)
	ELSE
		CURRENT_LIST '= "NGGYU"
	ENDIF
ELSE
	CURRENT_LIST '= ARGS
ENDIF

PIC_COUNT = 0
VARSET STR
VARSET LYRIC
VARSET TLYRIC
VARSET LYRIC_STRLEN
VARSET LYRIC_STRLENU
VARSET TLYRIC_STRLEN
VARSET LYRIC_START_TICK
VARSET LYRIC_END_TICK

CALL GET_GAME_TITLE

TRYCCALLFORM %CURRENT_LIST%
CATCH
	THROW %CURRENT_LIST% NOT FOUND
ENDCATCH

IF !GLOBAL
	GLOBAL = 1
	SAVEGLOBAL
ENDIF

LOCAL = GETMILLISECOND() - LOADING_OFFSET
SIF LOCAL < 1000
TWAIT 500 - RAND(LOCAL) + RAND(LOCAL), 0

CLEARLINE LINECOUNT

SETBGMVOLUME BGM_VOLUME
TRYCALLFORM PLAY_%CURRENT_LIST%
STOPSOUND

SIF START_DELAY_TICK
TWAIT START_DELAY_TICK, 0

START_TIME = GETMILLISECOND()

FOR LOCAL, 0, PIC_COUNT
	CLEARLINE LINECOUNT
	SIF MESSKIP()
	BREAK
	TIME_PASS = GETMILLISECOND() - START_TIME
	LOCAL = TIME_PASS / PIC_TICK
	SIF INRANGE(TIME_PASS, 4000, 12000)
	PRINTL [ 点击鼠标右键退出 ]
	PRINTL
	PRINTS STR:LOCAL
	CALL PRINT_PREPARE
	CALL PRINT_LYRIC
	CALL PRINT_LYRIC(1)
	TWAIT 40, 0
NEXT

SIF END_DELAY_TICK
TWAIT END_DELAY_TICK, 0

STOPBGM

;===========================================

@PRINT_PREPARE

#DIMS CONST _STR = "● "
#DIM CONST _STRLEN = 3

IF TIME_PASS >= LYRIC_START_TICK:CURRENT_LYRIC
	PRINTL
	RETURN
ENDIF

LOCAL = LYRIC_SHOW_TICK - (LYRIC_START_TICK:CURRENT_LYRIC - TIME_PASS)
IF LOCAL < LYRIC_FIRST_FADE_TICK
	SETCOLOR COLOR_BRIGHTNESS(HIGHLIGHT_COLOR, 100 * LOCAL / LYRIC_FIRST_FADE_TICK)
	PRINTSL _STR * 3 + " " * (PIC_LENS - 3 * _STRLEN)
ELSE
	SETCOLOR HIGHLIGHT_COLOR
	LOCAL = LYRIC_START_TICK:CURRENT_LYRIC - TIME_PASS
	IF LOCAL < 3000
		PRINTS _STR * (LOCAL / 1000)
		LOCAL:1 = 100 - (100 - 100 * (LOCAL % 1000) / 1000) * 1000 / 400
		SETCOLOR COLOR_BRIGHTNESS(HIGHLIGHT_COLOR, LOCAL:1)
		PRINTSL _STR + " " * (PIC_LENS - (LOCAL / 1000 + 1) * _STRLEN)
	ELSE
		PRINTSL _STR * 3 + " " * (PIC_LENS - 3 * _STRLEN)
	ENDIF
ENDIF

RESETCOLOR

;===========================================

@PRINT_LYRIC(_DIRECTION)

#DIM _DIRECTION
#DIM _LYRIC_IDX
#DIM _BRIGHT
#DIM _COLOR, 2
#DIMS _LYRIC_STR, 2

IF LYRIC_START_TICK:CURRENT_LYRIC - TIME_PASS > LYRIC_SHOW_TICK
	PRINTS "\n" * 2
	RETURN
ENDIF

LOCAL = LYRIC_START_TICK:(CURRENT_LYRIC + 1)
IF LOCAL > 0 && TIME_PASS >= LOCAL
	CURRENT_LYRIC ++
	LYRIC_DIRECTION = !LYRIC_DIRECTION
ENDIF

IF _DIRECTION == LYRIC_DIRECTION

	_LYRIC_IDX = CURRENT_LYRIC

	IF TIME_PASS >= LYRIC_START_TICK:_LYRIC_IDX
		LOCAL = LYRIC_START_TICK:_LYRIC_IDX
		LOCAL = 100 * (TIME_PASS - LOCAL) / (LYRIC_END_TICK:_LYRIC_IDX - LOCAL)
		LOCAL = LIMIT(LOCAL, 0, 100) * LYRIC_STRLENU:_LYRIC_IDX / 100

		_LYRIC_STR:0 '= SUBSTRINGU(LYRIC:_LYRIC_IDX, 0, LOCAL)
		_LYRIC_STR:1 '= SUBSTRINGU(LYRIC:_LYRIC_IDX, LOCAL, LYRIC_STRLENU:_LYRIC_IDX - LOCAL)

		_BRIGHT = 100
		_COLOR = HIGHLIGHT_COLOR
		_COLOR:1 = FONT_COLOR
	ELSE
		LOCAL = LYRIC_SHOW_TICK - (LYRIC_START_TICK:_LYRIC_IDX - TIME_PASS)
		IF LOCAL < LYRIC_FIRST_FADE_TICK
			_BRIGHT = 100 * LOCAL / LYRIC_FIRST_FADE_TICK
			_COLOR = COLOR_BRIGHTNESS(FONT_COLOR, _BRIGHT)
			_COLOR:1 = COLOR_BRIGHTNESS(FONT_COLOR, _BRIGHT)
		ELSE
			_BRIGHT = 100
			_COLOR = FONT_COLOR
			_COLOR:1 = FONT_COLOR
		ENDIF
		_LYRIC_STR:0 '= LYRIC:_LYRIC_IDX
		_LYRIC_STR:1 =
	ENDIF
ELSE
	IF !CURRENT_LYRIC
		_LYRIC_IDX = CURRENT_LYRIC + 1
		LOCAL = LYRIC_SHOW_TICK - (LYRIC_START_TICK:CURRENT_LYRIC - TIME_PASS)
		IF LOCAL < LYRIC_FIRST_FADE_TICK
			_BRIGHT = 100 * LOCAL / LYRIC_FIRST_FADE_TICK
			_COLOR = COLOR_BRIGHTNESS(FONT_COLOR, _BRIGHT)
			_COLOR:1 = COLOR_BRIGHTNESS(FONT_COLOR, _BRIGHT)
		ELSE
			_BRIGHT = 100
			_COLOR = FONT_COLOR
			_COLOR:1 = FONT_COLOR
		ENDIF
	ELSE
		LOCAL = LYRIC_END_TICK:CURRENT_LYRIC - TIME_PASS
		IF LOCAL > LYRIC_FADE_START_TICK
			_LYRIC_IDX = CURRENT_LYRIC - 1
			_BRIGHT = 100
			_COLOR = HIGHLIGHT_COLOR
			_COLOR:1 = FONT_COLOR
		ELSEIF LOCAL <= LYRIC_FADE_START_TICK - LYRIC_FADE_TICK * 2
			_LYRIC_IDX = CURRENT_LYRIC + 1
			_BRIGHT = 100
			_COLOR = FONT_COLOR
			_COLOR:1 = FONT_COLOR
		ELSE
			LOCAL = LYRIC_FADE_START_TICK - LOCAL
			IF LOCAL < LYRIC_FADE_TICK
				_LYRIC_IDX = CURRENT_LYRIC - 1
				_BRIGHT = 100 - (100 * LOCAL / LYRIC_FADE_TICK)
				_COLOR = COLOR_BRIGHTNESS(HIGHLIGHT_COLOR, _BRIGHT)
			ELSE
				_LYRIC_IDX = CURRENT_LYRIC + 1
				_BRIGHT = 100 * LOCAL / (LYRIC_FADE_TICK * 2)
				_COLOR = COLOR_BRIGHTNESS(FONT_COLOR, _BRIGHT)
			ENDIF
			_COLOR:1 = COLOR_BRIGHTNESS(FONT_COLOR, _BRIGHT)
		ENDIF
	ENDIF

	_LYRIC_STR:0 '= LYRIC:_LYRIC_IDX
	_LYRIC_STR:1 =
ENDIF

IF _BRIGHT
	IF _DIRECTION
		PRINTS " " * (PIC_LENS - LYRIC_STRLEN:_LYRIC_IDX)
		SETCOLOR _COLOR
		PRINTS _LYRIC_STR
		RESETCOLOR
		PRINTSL _LYRIC_STR:1
		SETCOLOR _COLOR:1
		PRINTSL " " * (PIC_LENS - TLYRIC_STRLEN:_LYRIC_IDX) + TLYRIC:_LYRIC_IDX
		RESETCOLOR
	ELSE
		SETCOLOR _COLOR
		PRINTS _LYRIC_STR
		RESETCOLOR
		PRINTSL _LYRIC_STR:1 + " " * (PIC_LENS - LYRIC_STRLEN:_LYRIC_IDX)
		SETCOLOR _COLOR:1
		PRINTSL TLYRIC:_LYRIC_IDX + " " * (PIC_LENS - TLYRIC_STRLEN:_LYRIC_IDX)
		RESETCOLOR
	ENDIF
ELSE
	PRINTS "\n" * 2
ENDIF

;===========================================

@ADDSTR(_ARGS)

#DIMS REF _ARGS

STR:(PIC_COUNT++) '= _ARGS
_ARGS =

SIF !(PIC_COUNT % 200)
AWAIT

;===========================================

@COLOR_BRIGHTNESS(ARG, BRIGHT)
#FUNCTION

#DIM BRIGHT

BRIGHT = LIMIT(BRIGHT, 0, 100)
LOCAL:0 = COLOR_RGB(ARG, 0) * BRIGHT / 100
LOCAL:1 = COLOR_RGB(ARG, 1) * BRIGHT / 100
LOCAL:2 = COLOR_RGB(ARG, 2) * BRIGHT / 100

RETURNF COLOR_FROMRGB(LOCAL:0, LOCAL:1, LOCAL:2)

;===========================================

@COLOR_RGB(ARG, ARG:1)
#FUNCTION

SIF !ARG:1
RETURNF (ARG & 0XFF0000) >> 16

SIF ARG:1 == 1
RETURNF (ARG & 0XFF00) >> 8

SIF ARG:1 == 2
RETURNF (ARG & 0XFF) >> 0

THROW ARGS: {ARG:1} NOT FOUND

;===========================================

@GET_GAME_TITLE

LOCALS =
LOCALS += "    ______                    ____                               " + "\n"
LOCALS += "   / ____/   _____  ____ _   / __ ╰  ____    ____ _  __  __  ___ " + "\n"
LOCALS += "  / __/     / ___/ / __ `/  / /_/ / / __ ╰  / __ `/ / / / / / _ ╰" + "\n"
LOCALS += " / /___    / /    / /_/ /  / _, _/ / /_/ / / /_/ / / /_/ / /  __/" + "\n"
LOCALS += "/_____/   /_/     ╰__,_/  /_/ |_|  ╰____/  ╰__, /  ╰__,_/  ╰___/ " + "\n"
LOCALS += "    ___     __    __                      /____/                 " + "\n"
LOCALS += "   /   |   / /   / /  ___    ____ _  ____    _____   __  __      " + "\n"
LOCALS += "  / /| |  / /   / /  / _ ╰  / __ `/ / __ ╰  / ___/  / / / /      " + "\n"
LOCALS += " / ___ | / /   / /  /  __/ / /_/ / / /_/ / / /     / /_/ /       " + "\n"
LOCALS += "/_/  |_|/_/   /_/   ╰___/  ╰__, /  ╰____/ /_/      ╰__, /        " + "\n"
LOCALS += "                          /____/                  /____/         " + "\n"
LOCALS:1 = ～Northern Galaxy's Glorious Yolkel Union～

GAME_TITLE '= LOCALS
GAME_TITLE:1 '= LOCALS:1

;===========================================

; @RECORD_TICK

; CALL TEXT_KMHBRYRUTKS
; LOCAL:2 = VARSIZE("LYRIC") - MATCH(LYRIC, "")
; SETBGMVOLUME 40
; PLAYBGM "KMHBRYRUTKS.aac"
; TWAIT 600, 0
; LOCAL:1 = GETMILLISECOND()
; FOR LOCAL, 0, LOCAL:2
	; SETCOLOR HIGHLIGHT_COLOR
	; PRINTSL LYRIC:LOCAL
	; PRINTSL "NEXT_LYRIC: " + LYRIC:(LOCAL + 1)
	; RESETCOLOR
	; PRINTL
	; PRINTL PRESS TO START
	; WAITANYKEY
	; A:LOCAL = GETMILLISECOND() - LOCAL:1
	; PRINTL
	; PRINTL PRESS TO END
	; WAITANYKEY
	; B:LOCAL = GETMILLISECOND() - LOCAL:1
; NEXT
; FOR LOCAL, 0, LOCAL:2
	; PRINTFORML {A:LOCAL}
; NEXT
; PRINTL
; PRINTL
; FOR LOCAL, 0, LOCAL:2
	; PRINTFORML {B:LOCAL}
; NEXT
; STOPBGM
; INPUT
; VARSET A
; VARSET B
; RESTART
